/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.gui;

import br.com.controllers.Controller;
import br.com.models.Days;
import br.com.models.Graduation;
import br.com.models.Teacher;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.ParseException;
import java.util.ArrayList;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.text.MaskFormatter;

/**
 *
 * @author Valdigleis
 */
public class EditWindowTeacher extends javax.swing.JDialog {

    private JDialog anteced;
    
    private JFrame parent;
    
    private Teacher teacher;
    
    private Teacher editTeacher;
    
    private Graduation graduation;
    
    private ArrayList<Days> days;
    
    private MaskFormatter formatterName;
    
    private MaskFormatter formatterRegister;
    
    private String sucess;
    
    /**
     * Metodo construtor da classe EditWindowTeacher.
     */
    public EditWindowTeacher(JDialog anteced, JFrame parent, Teacher teacher) {
        super(parent, true);
        this.formatterName = new MaskFormatter();
        this.formatterRegister = new MaskFormatter();
        this.anteced = anteced;
        this.parent = parent;
        this.teacher = teacher;
        this.editTeacher = new Teacher();
        this.graduation = new Graduation();
        this.days = new ArrayList<Days>();
        initComponents();
        try{
            formatterName.setMask("U*****************************");
            formatterName.setInvalidCharacters("0123456789!?/|[]{}ªº°");
            formatterName.install(nameTeacherField);
            formatterRegister.setMask("######");
            formatterRegister.install(registerTeacherField);
        }catch(ParseException e){
            System.out.println(e.getMessage());
        }
        setResizable(false);
        this.day1Label.setText("");
        this.day2Label.setText("");
        this.day3Label.setText("");
        this.day4Label.setText("");
        this.day5Label.setText("");
        this.nameTeacherLabel.setText(teacher.getName());
        this.registerTeacherLabel.setText(teacher.getRegister());
        this.graduationLabel.setText(teacher.getGraduation().getLevel());
        this.graduationStatusLabel.setText(teacher.getGraduation().getSituation());
        this.timeJlabel.setText(Integer.toString(teacher.getGraduation().getTime()));
        for(int i = 0; i < teacher.getDays().size(); i++){
            if(this.day1Label.getText().equals("")){
                this.day1Label.setText(teacher.getDays().get(i).getName());
            }else{
                if(this.day2Label.getText().equals("")){
                    this.day2Label.setText(teacher.getDays().get(i).getName());
                }else{
                    if(this.day3Label.getText().equals("")){
                        this.day3Label.setText(teacher.getDays().get(i).getName());
                    }else{
                        if(this.day4Label.getText().equals("")){
                            this.day4Label.setText(teacher.getDays().get(i).getName());
                        }else{
                            this.day5Label.setText(teacher.getDays().get(i).getName());
                        }
                    }
                }
            }
        }
        this.nameTeacherField.setText("");
        this.registerTeacherField.setText("");
        this.jRadioButton1.setActionCommand("Mestrado");
        this.jRadioButton2.setActionCommand("Doutorado");
        this.jRadioButton3.setActionCommand("Pós-doutorado");
        this.jRadioButton4.setActionCommand("Em Andamento");
        this.jRadioButton5.setActionCommand("Concluído");
        this.jRadioButton6.setActionCommand("Abandonado");
        this.jCheckBox1.setActionCommand("0");
        this.jCheckBox2.setActionCommand("1");
        this.jCheckBox3.setActionCommand("2");
        this.jCheckBox4.setActionCommand("3");
        this.jCheckBox5.setActionCommand("4");
        this.jCheckBox6.setActionCommand("5");
        this.jCheckBox7.setActionCommand("6");
        this.jCheckBox8.setActionCommand("7");
        this.jCheckBox9.setActionCommand("8");
        
        this.jRadioButton4.addActionListener(new ActionListener(){
            @Override
            public void actionPerformed(ActionEvent e){
                if(jRadioButton4.isSelected()){
                    jCheckBox1.setEnabled(true);
                    jCheckBox2.setEnabled(true);
                    jCheckBox3.setEnabled(true);
                    jCheckBox4.setEnabled(true);
                    jCheckBox5.setEnabled(true);
                    jCheckBox6.setEnabled(true);
                    jCheckBox7.setEnabled(true);
                    jCheckBox8.setEnabled(true);
                    jCheckBox9.setEnabled(true);
                }
            }
           }
        );
        
        this.jRadioButton5.addActionListener(new ActionListener(){
            @Override
            public void actionPerformed(ActionEvent e){
                if(jRadioButton5.isSelected()){
                    jCheckBox1.setSelected(true);
                    jCheckBox1.setEnabled(false);
                    jCheckBox2.setEnabled(false);
                    jCheckBox3.setEnabled(false);
                    jCheckBox4.setEnabled(false);
                    jCheckBox5.setEnabled(false);
                    jCheckBox6.setEnabled(false);
                    jCheckBox7.setEnabled(false);
                    jCheckBox8.setEnabled(false);
                    jCheckBox9.setEnabled(false);
                }
            }
           }
        );
        this.jRadioButton6.addActionListener(new ActionListener(){
            @Override
            public void actionPerformed(ActionEvent e){
                if(jRadioButton6.isSelected()){
                    jCheckBox1.setSelected(true);
                    jCheckBox1.setEnabled(false);
                    jCheckBox2.setEnabled(false);
                    jCheckBox3.setEnabled(false);
                    jCheckBox4.setEnabled(false);
                    jCheckBox5.setEnabled(false);
                    jCheckBox6.setEnabled(false);
                    jCheckBox7.setEnabled(false);
                    jCheckBox8.setEnabled(false);
                    jCheckBox9.setEnabled(false);
                }
            }
           }
        );
        this.jRadioButton7.setActionCommand("Segunda-feira");
        this.jRadioButton8.setActionCommand("Terça-feira");
        this.jRadioButton9.setActionCommand("Quarta-feira");
        this.jRadioButton10.setActionCommand("Quinta-feira");
        this.jRadioButton11.setActionCommand("Sexta-feira");
        Rectangle parentBounds = parent.getBounds();
        Dimension size = getSize();
        // Center in the parent
        int x = Math.max(0, parentBounds.x + (parentBounds.width - size.width) / 2);
        int y = Math.max(0, parentBounds.y + (parentBounds.height - size.height) / 2);
        setLocation(new Point(x, y));
        setVisible(true);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jDesktopPane1 = new javax.swing.JDesktopPane();
        GrupeFormation = new javax.swing.ButtonGroup();
        GrupeStatusFormation = new javax.swing.ButtonGroup();
        GrupeTime = new javax.swing.ButtonGroup();
        jInternalFrame2 = new javax.swing.JInternalFrame();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jRadioButton1 = new javax.swing.JRadioButton();
        jRadioButton2 = new javax.swing.JRadioButton();
        jRadioButton3 = new javax.swing.JRadioButton();
        jRadioButton4 = new javax.swing.JRadioButton();
        jRadioButton5 = new javax.swing.JRadioButton();
        jRadioButton6 = new javax.swing.JRadioButton();
        jLabel14 = new javax.swing.JLabel();
        jCheckBox1 = new javax.swing.JCheckBox();
        jCheckBox2 = new javax.swing.JCheckBox();
        jCheckBox3 = new javax.swing.JCheckBox();
        jCheckBox4 = new javax.swing.JCheckBox();
        jCheckBox5 = new javax.swing.JCheckBox();
        jCheckBox6 = new javax.swing.JCheckBox();
        jCheckBox7 = new javax.swing.JCheckBox();
        jCheckBox8 = new javax.swing.JCheckBox();
        jCheckBox9 = new javax.swing.JCheckBox();
        nameTeacherField = new javax.swing.JFormattedTextField();
        registerTeacherField = new javax.swing.JFormattedTextField();
        jButton2 = new javax.swing.JButton();
        jLabel15 = new javax.swing.JLabel();
        jRadioButton7 = new javax.swing.JRadioButton();
        jRadioButton8 = new javax.swing.JRadioButton();
        jRadioButton9 = new javax.swing.JRadioButton();
        jRadioButton10 = new javax.swing.JRadioButton();
        jRadioButton11 = new javax.swing.JRadioButton();
        jLabel2 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        nameTeacherLabel = new javax.swing.JLabel();
        registerTeacherLabel = new javax.swing.JLabel();
        graduationLabel = new javax.swing.JLabel();
        graduationStatusLabel = new javax.swing.JLabel();
        day2Label = new javax.swing.JLabel();
        day3Label = new javax.swing.JLabel();
        day4Label = new javax.swing.JLabel();
        day5Label = new javax.swing.JLabel();
        day1Label = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        timeJlabel = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Módulo de edição de professor.");

        jInternalFrame2.setTitle("Campo de Edição");
        jInternalFrame2.setToolTipText("");
        jInternalFrame2.setVisible(true);

        jLabel9.setText("Entre com as novas informações");

        jLabel10.setText("Nome:");

        jLabel11.setText("Matrícula:");

        jLabel12.setText("Formação Atual:");

        jLabel13.setText("Status da Formação:");

        GrupeFormation.add(jRadioButton1);
        jRadioButton1.setText("Mestrado");

        GrupeFormation.add(jRadioButton2);
        jRadioButton2.setText("Doutorado");

        GrupeFormation.add(jRadioButton3);
        jRadioButton3.setText("Pós-doutorado");
        jRadioButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton3ActionPerformed(evt);
            }
        });

        GrupeStatusFormation.add(jRadioButton4);
        jRadioButton4.setText("Em Andamento");

        GrupeStatusFormation.add(jRadioButton5);
        jRadioButton5.setText("Concluído");
        jRadioButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton5ActionPerformed(evt);
            }
        });

        GrupeStatusFormation.add(jRadioButton6);
        jRadioButton6.setText("Abandonado");

        jLabel14.setText("Semestre para concluir:");

        GrupeTime.add(jCheckBox1);
        jCheckBox1.setText("0");

        GrupeTime.add(jCheckBox2);
        jCheckBox2.setText("1");

        GrupeTime.add(jCheckBox3);
        jCheckBox3.setText("2");

        GrupeTime.add(jCheckBox4);
        jCheckBox4.setText("3");

        GrupeTime.add(jCheckBox5);
        jCheckBox5.setText("4");

        GrupeTime.add(jCheckBox6);
        jCheckBox6.setText("5");

        GrupeTime.add(jCheckBox7);
        jCheckBox7.setText("6");

        GrupeTime.add(jCheckBox8);
        jCheckBox8.setText("7");

        GrupeTime.add(jCheckBox9);
        jCheckBox9.setText("8");

        jButton2.setText("Aualizar Informações");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jLabel15.setText("Selecione os dias de expediente:");

        jRadioButton7.setText("Segunda-feira");

        jRadioButton8.setText("Terça-feira");

        jRadioButton9.setText("Quarta-feira");

        jRadioButton10.setText("Quinta-feira");

        jRadioButton11.setText("Sexta-feira");

        javax.swing.GroupLayout jInternalFrame2Layout = new javax.swing.GroupLayout(jInternalFrame2.getContentPane());
        jInternalFrame2.getContentPane().setLayout(jInternalFrame2Layout);
        jInternalFrame2Layout.setHorizontalGroup(
            jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jInternalFrame2Layout.createSequentialGroup()
                .addGroup(jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jInternalFrame2Layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addGroup(jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jRadioButton3)
                            .addComponent(jRadioButton2)
                            .addComponent(jRadioButton1)))
                    .addGroup(jInternalFrame2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel14))
                    .addGroup(jInternalFrame2Layout.createSequentialGroup()
                        .addGap(78, 78, 78)
                        .addComponent(jButton2))
                    .addGroup(jInternalFrame2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jInternalFrame2Layout.createSequentialGroup()
                                .addComponent(jLabel12)
                                .addGap(69, 69, 69)
                                .addGroup(jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jRadioButton4)
                                    .addComponent(jRadioButton5)
                                    .addComponent(jRadioButton6)
                                    .addComponent(jLabel13)))
                            .addGroup(jInternalFrame2Layout.createSequentialGroup()
                                .addComponent(jCheckBox1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jCheckBox2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jCheckBox3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jCheckBox4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jCheckBox5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jCheckBox6)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jCheckBox7)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jCheckBox8)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jCheckBox9))))
                    .addGroup(jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jInternalFrame2Layout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(jLabel11)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(registerTeacherField))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jInternalFrame2Layout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(jLabel10)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(nameTeacherField))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jInternalFrame2Layout.createSequentialGroup()
                            .addGap(52, 52, 52)
                            .addComponent(jLabel9)))
                    .addGroup(jInternalFrame2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel15, javax.swing.GroupLayout.PREFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jInternalFrame2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jInternalFrame2Layout.createSequentialGroup()
                                .addGap(21, 21, 21)
                                .addComponent(jRadioButton10)
                                .addGap(18, 18, 18)
                                .addComponent(jRadioButton11))
                            .addGroup(jInternalFrame2Layout.createSequentialGroup()
                                .addComponent(jRadioButton7)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jRadioButton8)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jRadioButton9)))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jInternalFrame2Layout.setVerticalGroup(
            jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jInternalFrame2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel9)
                .addGap(18, 18, 18)
                .addGroup(jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(nameTeacherField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(registerTeacherField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(8, 8, 8)
                .addGroup(jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(jLabel13))
                .addGap(7, 7, 7)
                .addGroup(jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jRadioButton1)
                    .addComponent(jRadioButton4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jRadioButton2)
                    .addComponent(jRadioButton5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jRadioButton3)
                    .addComponent(jRadioButton6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel14)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jCheckBox1)
                    .addComponent(jCheckBox2)
                    .addComponent(jCheckBox3)
                    .addComponent(jCheckBox4)
                    .addComponent(jCheckBox5)
                    .addComponent(jCheckBox6)
                    .addComponent(jCheckBox7)
                    .addComponent(jCheckBox8)
                    .addComponent(jCheckBox9))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel15)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jRadioButton7)
                    .addComponent(jRadioButton8)
                    .addComponent(jRadioButton9))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jRadioButton10)
                    .addComponent(jRadioButton11))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButton2)
                .addGap(20, 20, 20))
        );

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resource/teacher.png"))); // NOI18N
        jLabel2.setText("jLabel2");

        jLabel1.setText("Informações Atuais do Professor");

        jLabel3.setText("Nome:");

        jLabel4.setText("Matrícula:");

        jLabel5.setText("Formação Atual:");

        jLabel6.setText("Status da Formação:");

        jLabel7.setText("Dias de Expediente:");

        graduationStatusLabel.setText("jLabel8");

        day2Label.setText("jLabel8");

        day3Label.setText("jLabel8");

        day4Label.setText("jLabel8");

        day5Label.setText("jLabel8");

        day1Label.setText("jLabel8");

        jLabel8.setText("Semestre para concluir:");

        timeJlabel.setText("jLabel9");

        jButton1.setText("Manter dados atuais");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(32, 32, 32)
                        .addComponent(jLabel1))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(nameTeacherLabel))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(graduationLabel))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(day5Label))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(day4Label))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(day3Label))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(day2Label))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(day1Label))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel6)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(graduationStatusLabel))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(44, 44, 44)
                                .addComponent(jButton1))))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(registerTeacherLabel)))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel7)
                            .addComponent(jLabel8))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(timeJlabel)))
                .addGap(18, 18, 18)
                .addComponent(jInternalFrame2)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(17, 17, 17)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel2)
                .addGap(29, 29, 29)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(nameTeacherLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(registerTeacherLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(graduationLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(graduationStatusLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(timeJlabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel7)
                .addGap(1, 1, 1)
                .addComponent(day1Label)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(day2Label)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(day3Label)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(day4Label)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(day5Label)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addGap(30, 30, 30))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jInternalFrame2)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jRadioButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton5ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jRadioButton5ActionPerformed

    private void jRadioButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton3ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jRadioButton3ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        this.dispose();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        this.editTeacher.setId(teacher.getId());
        this.graduation.setId(teacher.getGraduation().getId());
        if(checkAllFields() == 1){
            refreshTeacher();
            Controller controller = new Controller();
            if(this.editTeacher.getRegister().equals(this.teacher.getRegister())){
                controller.updateTeacher(this.editTeacher);
                JOptionPane.showMessageDialog(parent, this.sucess);
                this.anteced.dispose();
                this.dispose();
            }else{
                if(controller.checkRegister(this.editTeacher.getRegister())){
                    JOptionPane.showMessageDialog(parent, "Esta matricula já está em uso por outro professor");
                }else{
                    controller.updateTeacher(this.editTeacher);
                    JOptionPane.showMessageDialog(parent, this.sucess);
                    this.anteced.dispose();
                    this.dispose();
                }
            }
        }else{
            JOptionPane.showMessageDialog(parent, this.sucess);
        }
    }//GEN-LAST:event_jButton2ActionPerformed

    private int checkAllFields(){
        this.days.clear();
        int controll = 0;
        int err = 0;
        this.sucess = "Os campos:\n";
        if(checkFieldName()){
            this.editTeacher.setName(nameTeacherField.getText().trim());
            controll = 1;
            this.sucess = sucess.concat("Nome\n");
        }
        if(checkFieldRegister()){
            this.editTeacher.setRegister(registerTeacherField.getText().trim());
            controll = 1;
            this.sucess = sucess.concat("Matricula\n");
        }
        if(checkFieldFormation()){
            this.graduation.setLevel(GrupeFormation.getSelection().getActionCommand());
            controll = 1;
            this.sucess = sucess.concat("Formação\n");
        }
        //---------------------
        if(checkFieldStatus()){
            if(getFieldStatus() == 0 && jCheckBox1.isSelected()){
                err = 1;
            }else{
                if(getFieldStatus() > 0 && timeConclusion()){
                    err = 1;
                }else{
                    this.graduation.setSituation(GrupeStatusFormation.getSelection().getActionCommand());
                    this.graduation.setTime(Integer.parseInt(GrupeTime.getSelection().getActionCommand()));
                    controll = 1;
                    this.sucess = sucess.concat("Status da Formação\nTempo de conclusão\n");
                }
            }
        }
        if(checkFieldDays()){
            getDays();
            controll = 1;
            this.sucess = sucess.concat("Expediente\n");
        }
        if(controll == 1 && err == 0){
            this.sucess = sucess.concat("Atualizados com sucesso");
            this.editTeacher.setGraduation(this.graduation);
            this.editTeacher.setDays(this.days);
            return 1;
        }else{
            if(err == 1){
                this.sucess = "Erro verifique o Status da formação e o tempo de conclusão!";
                return 2;
            }else{
                this.sucess = "Nenhuma atualização foi informada!";
                return 3;
            }
        }
    }
    
    private boolean checkFieldName(){
        return !(nameTeacherField.getText().trim().equals(""));
    }
    
    private boolean checkFieldRegister(){
        return !(registerTeacherField.getText().trim().equals(""));
    }
    
    private boolean checkFieldFormation(){
        return (jRadioButton1.isSelected() || jRadioButton2.isSelected() || jRadioButton3.isSelected());
    }
    
    private boolean checkFieldStatus(){
        return (jRadioButton4.isSelected() || jRadioButton5.isSelected() || jRadioButton6.isSelected());
    }
    
    private int getFieldStatus(){
        if(jRadioButton4.isSelected()){
            return 0;
        }else{
            if(jRadioButton5.isSelected()){
                return 1;
            }else{
                return 2;
            }
        }
    }
    
    private boolean timeConclusion(){
        return (jCheckBox2.isSelected() || jCheckBox3.isSelected() || jCheckBox4.isSelected() ||
                jCheckBox5.isSelected() || jCheckBox6.isSelected() || jCheckBox7.isSelected() ||
                jCheckBox8.isSelected());
    }
    
    private boolean checkFieldDays(){
        return (jRadioButton7.isSelected() || jRadioButton8.isSelected() || jRadioButton9.isSelected() ||
                jRadioButton10.isSelected()  || jRadioButton11.isSelected() );
    }
    
    private boolean testStatus(String status){
        return (status.equals("Concluído") || status.equals("Abandonado"));
    }
    
    private boolean testTime(String time){
        return (time.equals("0"));
    }
    
    private void getDays(){
        if(jRadioButton7.isSelected()){
            Days day = new Days();
            day.setName(jRadioButton7.getActionCommand());
            this.days.add(day);
        }
        if(jRadioButton8.isSelected()){
            Days day = new Days();
            day.setName(jRadioButton8.getActionCommand());
            this.days.add(day);
        }
        if(jRadioButton9.isSelected()){
            Days day = new Days();
            day.setName(jRadioButton9.getActionCommand());
            this.days.add(day);
        }
        if(jRadioButton10.isSelected()){
            Days day = new Days();
            day.setName(jRadioButton10.getActionCommand());
            this.days.add(day);
        }
        if(jRadioButton11.isSelected()){
            Days day = new Days();
            day.setName(jRadioButton11.getActionCommand());
            this.days.add(day);
        }
    }
    
    private void refreshTeacher(){
        if(this.editTeacher.getName() == null){
            this.editTeacher.setName(this.teacher.getName());
        }
        if(this.editTeacher.getRegister() == null){
            this.editTeacher.setRegister(this.teacher.getRegister());
        }
        if(this.editTeacher.getGraduation().getLevel() == null){
            this.editTeacher.getGraduation().setLevel(this.teacher.getGraduation().getLevel());
        }
        if(this.editTeacher.getGraduation().getSituation() == null){
            this.editTeacher.getGraduation().setSituation(this.teacher.getGraduation().getSituation());
            this.editTeacher.getGraduation().setTime(this.teacher.getGraduation().getTime());
        }
        if(this.editTeacher.getDays().isEmpty()){
            this.editTeacher.setDays(this.teacher.getDays());
        }
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup GrupeFormation;
    private javax.swing.ButtonGroup GrupeStatusFormation;
    private javax.swing.ButtonGroup GrupeTime;
    private javax.swing.JLabel day1Label;
    private javax.swing.JLabel day2Label;
    private javax.swing.JLabel day3Label;
    private javax.swing.JLabel day4Label;
    private javax.swing.JLabel day5Label;
    private javax.swing.JLabel graduationLabel;
    private javax.swing.JLabel graduationStatusLabel;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JCheckBox jCheckBox2;
    private javax.swing.JCheckBox jCheckBox3;
    private javax.swing.JCheckBox jCheckBox4;
    private javax.swing.JCheckBox jCheckBox5;
    private javax.swing.JCheckBox jCheckBox6;
    private javax.swing.JCheckBox jCheckBox7;
    private javax.swing.JCheckBox jCheckBox8;
    private javax.swing.JCheckBox jCheckBox9;
    private javax.swing.JDesktopPane jDesktopPane1;
    private javax.swing.JInternalFrame jInternalFrame2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton10;
    private javax.swing.JRadioButton jRadioButton11;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JRadioButton jRadioButton3;
    private javax.swing.JRadioButton jRadioButton4;
    private javax.swing.JRadioButton jRadioButton5;
    private javax.swing.JRadioButton jRadioButton6;
    private javax.swing.JRadioButton jRadioButton7;
    private javax.swing.JRadioButton jRadioButton8;
    private javax.swing.JRadioButton jRadioButton9;
    private javax.swing.JFormattedTextField nameTeacherField;
    private javax.swing.JLabel nameTeacherLabel;
    private javax.swing.JFormattedTextField registerTeacherField;
    private javax.swing.JLabel registerTeacherLabel;
    private javax.swing.JLabel timeJlabel;
    // End of variables declaration//GEN-END:variables
}
